home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / 2m21src.zip / 2MF.C < prev    next >
C/C++ Source or Header  |  1994-05-31  |  33KB  |  939 lines

  1.  
  2. /*───────────────────────────────────────────────────────────────────\
  3. │                                                                    │
  4. │                         █████ █   █ █▀▀▀▀                          │
  5. │                             █ ██ ██ █                              │
  6. │                         █████ █ █ █ █▀▀                            │
  7. │                         █     █   █ █                              │
  8. │                         █████ █   █ █                              │
  9. │                                                                    │
  10. │        2MF.C  2.1  -  UTILIDAD DE FORMATEO DE DISQUETES 2M         │
  11. │                                                                    │
  12. │                  (c) 1994 Ciriaco García de Celis.                 │
  13. │                                                                    │
  14. │   - Para Borland C++ 2.0 ó superior en modelo de memoria LARGE.    │
  15. │   - Este programa se compila abriendo un proyecto e introduciendo  │
  16. │     en él 2MF.C, 2MFKIT.OBJ, 2MFBOTHD.OBJ y 2MFBOTDD.OBJ           │
  17. │                                                                    │
  18. │   - NOTA: Las funciones de bajo nivel que acceden directamente a   │
  19. │           la controladora de disquetes no son indispensables, tan  │
  20. │           sólo se emplean para producir menos ruido al detectar    │
  21. │           la introducción de un nuevo disquete en la unidad.       │
  22. │                                                                    │
  23. \───────────────────────────────────────────────────────────────────*/
  24.  
  25.  
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <dos.h>
  30. #include <bios.h>
  31. #include <time.h>
  32. #include <alloc.h>
  33.  
  34. unsigned _stklen=16384;
  35.  
  36. #define MAXSECT      46   /* máximo número de sectores por pista */
  37. #define MAXFAT     6128   /* mayor FAT de 12 bits posible */
  38. #define FD_DATA   0x3F5   /* registro de datos del 765 */
  39. #define FD_STATUS 0x3F4   /* registro principal de estado del 765 */
  40. #define FD_DOR    0x3F2   /* registro de salida digital */
  41. #define FD_DIR    0x3F7      /* registro de entrada digital (RD) */
  42. #define FD_DCR    0x3F7      /* registro de control del disquete (WR) */
  43.  
  44.  
  45. struct boot {                       /* sector arranque disquetes 2M */
  46.   unsigned char Salto[3], IdSis[8];
  47.   short    BytesSect;
  48.   char     SectCluster;
  49.   short    SectReserv;
  50.   char     NumFats;
  51.   short    FichRaiz, NumSect;
  52.   char     MediaId;
  53.   short    SectFat, SectPista, Caras;
  54.   long     Especiales, Sect32;
  55.   char     Unidad, Reservado, Flag;
  56.   long     NumSerie;
  57.   char     Titulo[11], TipoFat[8];
  58.   char     NoUsado;
  59.   char     CheckSum;
  60.   char     VersionFmt, FlagWr, VelPista0, VelPistaX;
  61.   short    OffsetJmp, OffsetPista0, OffsetPistaX, OffsetListaTam;
  62.   char     Resto[512-76];
  63.   };
  64.  
  65. struct parametros {              /* parámetros en línea de comandos */
  66.   int   Unidad, HD, ED, TipoFmt, NoVerify, MarcaPoco,
  67.         Pistas, FichRaiz, Silencioso, NoPausa, X, Y, G;
  68.   };
  69.  
  70.  
  71. int    HablaSp(), Hay2m(), Hay2mBoot(), FormatearDisco(), MarcaFat(),
  72.        TipoDrive(), InicializaDisco(), EsperarCambioDisco(), infdc();
  73. void   Ayuda(), ProcesarParametros(), CrearSector0(),
  74.        DiagnosticoError(), InformeError(), InformeDisco(),
  75.        SonidoSube(), SonidoBaja(), SonidoError(), SonidoOn(),
  76.        SonidoOff(), Sonido(), posicionar(), outfdc(), EsperarInt();
  77. extern BootHDPrg, BootHDPrgLong, BootDDPrg, BootDDPrgLong,
  78.        Boot2mCode, Boot2mLong, biosdsk();
  79. extern void PicoRetardo();
  80.  
  81.  
  82. int      sp;                  /* 1-español 0-inglés */
  83. unsigned char far *fat;       /* para contener toda la FAT */
  84. unsigned char far *buffer;    /* para contener toda una pista */
  85.  
  86. unsigned long far *cbios=MK_FP(0x40, 0x6C);  /* reloj del sistema */
  87. unsigned char far *irq6=MK_FP(0x40, 0x3E);   /* flag BIOS de IRQ6 */
  88.  
  89.  
  90. void main (int argc, char **argv)
  91. {
  92.   struct boot sector0;
  93.   struct parametros cmd;
  94.   int    salir, result, sg;
  95.   long   bytes_err, dir;
  96.  
  97.   sp=HablaSp();  /* determinar idioma del país */
  98.  
  99.   ProcesarParametros (argc, argv, &cmd);
  100.  
  101.   if (!Hay2m())
  102.       if (!Hay2mBoot()) {
  103.         if (sp)
  104.             printf("  2M ó 2MX 2.1 no está instalado, imposible formatear.\n");
  105.           else
  106.             printf("  2M or 2MX 2.1 is not installed, impossible to format.\n");
  107.         exit(128);
  108.         }
  109.       else {
  110.         if (sp)
  111.             printf("  Modo SuperBOOT: instale 2M para dar formato.\n");
  112.           else
  113.             printf("  SuperBOOT mode: needed to install 2M to format.\n");
  114.         exit(127);
  115.         }
  116.  
  117.   if (((fat=farmalloc( (unsigned long) MAXFAT))==NULL) ||
  118.       ((buffer=farmalloc( (unsigned long) MAXSECT<<10))==NULL)) {
  119.       if (sp) printf("  Memoria insuficiente.\n");
  120.         else printf("  Insufficient memory.\n");
  121.       exit(126);
  122.       }
  123.  
  124.   /* Definir el buffer para que no cruce una frontera de DMA */
  125.  
  126.   dir = ((unsigned long) FP_SEG(buffer) <<4) + FP_OFF(buffer);
  127.   if ((dir >> 16) != ((dir + ((unsigned long) MAXSECT << 9)) >> 16))
  128.     buffer+=(unsigned long) MAXSECT << 9;
  129.  
  130.   if (!cmd.NoPausa) {
  131.       if (sp)
  132.           printf("  Pulsa una tecla para formatear en");
  133.         else
  134.           printf("  Press any key to format on");
  135.       printf(" %c:", cmd.Unidad+'A');
  136.       salir=getch()==27;
  137.       }
  138.     else
  139.       salir=0;
  140.  
  141.   while (!salir) {
  142.     CrearSector0 (§or0, cmd);
  143.     if (!cmd.Silencioso) SonidoSube();
  144.     switch (result=FormatearDisco (§or0, &cmd, &bytes_err, &sg)) {
  145.       case 0:  InformeDisco (§or0, bytes_err, sg);
  146.                if (!cmd.Silencioso) SonidoBaja(); break;
  147.       case 1:  DiagnosticoError (result);
  148.                break;
  149.       default: DiagnosticoError (result);
  150.                if (!cmd.Silencioso) SonidoError(); break;
  151.       }
  152.     if (sp)
  153.         printf("\n  Introduce otro disquete para formatear en");
  154.       else
  155.         printf("\n  Please insert another disk to format in");
  156.     printf(" %c:", cmd.Unidad+'A');
  157.  
  158.     if (!EsperarCambioDisco(cmd.Unidad)) salir=1;
  159.     }
  160.   printf("\r                                                     \r");
  161. }
  162.  
  163.  
  164. void ProcesarParametros(int argc, char **argv, struct parametros *cmd)
  165. {
  166.   int pm, error=0, hlp=0, id=1;
  167.  
  168.   cmd->Unidad=cmd->TipoFmt=cmd->ED=cmd->NoVerify=cmd->MarcaPoco=0;
  169.   cmd->HD=1; cmd->Pistas=82;
  170.   cmd->FichRaiz=cmd->Silencioso=cmd->NoPausa=0;
  171.   cmd->X=cmd->Y=cmd->G=-1;
  172.   for (pm=1; pm<argc; pm++) {
  173.     strupr (argv[pm]);
  174.     if (strstr(argv[pm],"/?")!=NULL) hlp++;
  175.     else if (strstr(argv[pm],"/H")!=NULL) hlp++;
  176.     else if ((strstr(argv[pm],"A:")!=NULL) ||
  177.       (strstr(argv[pm],"B:")!=NULL)) cmd->Unidad=*argv[pm]-'A';
  178.     else if (strstr(argv[pm],"/DD")!=NULL) cmd->HD=0;
  179.     else if (strstr(argv[pm],"/D0")!=NULL) cmd->HD=2;
  180.     else if (strstr(argv[pm],"/D1")!=NULL) cmd->HD=3;
  181.     else if (strstr(argv[pm],"/F")!=NULL) cmd->TipoFmt=0;
  182.     else if (strstr(argv[pm],"/M")!=NULL) cmd->TipoFmt=1;
  183.     else if (strstr(argv[pm],"/E")!=NULL) cmd->ED=1;
  184.     else if (strstr(argv[pm],"/N")!=NULL) cmd->NoVerify=1;
  185.     else if (strstr(argv[pm],"/W")!=NULL) cmd->MarcaPoco=1;
  186.     else if (strstr(argv[pm],"/T")!=NULL)
  187.       cmd->Pistas = atoi (&argv[pm][3]);
  188.     else if (strstr(argv[pm],"/R")!=NULL)
  189.       cmd->FichRaiz = atoi (&argv[pm][3]);
  190.     else if (strstr(argv[pm],"/S")!=NULL) { cmd->Silencioso=1; id++; }
  191.     else if (strstr(argv[pm],"/K")!=NULL) cmd->NoPausa=1;
  192.     else if (strstr(argv[pm],"/X")!=NULL) cmd->X=atoi(&argv[pm][3]);
  193.     else if (strstr(argv[pm],"/Y")!=NULL) cmd->Y=atoi(&argv[pm][3]);
  194.     else if (strstr(argv[pm],"/G")!=NULL) cmd->G=atoi(&argv[pm][3]);
  195.     else if (strstr(argv[pm],"/I")!=NULL) { sp^=1; id++; }
  196.     else error=1;
  197.     }
  198.  
  199.   if (cmd->ED && (cmd->HD!=1)) cmd->HD=1;  /* /DD ó /Dx + /E = /E */
  200.  
  201.   if ((argc<=1) || (argc==id)) hlp++;
  202.  
  203.   if (hlp) Ayuda();
  204.  
  205.   if (sp)
  206.       printf("\n2MF 2.1 - Utilidad de formateo de disquetes 2M         (ESC Salir)\n");
  207.     else
  208.       printf("\n2MF 2.1 - Format utility program for 2M diskettes      (ESC Aborts)\n");
  209.   if (error) {
  210.     if (sp)
  211.         printf("  Error de sintaxis. E